home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 1: Comms & Networking / Almathera Ten on Ten - Disc 1: Comms & Networking.iso / amiga-useful / multiuser / editusers / editusers.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  36KB  |  1,424 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <error.h>
  7.  
  8. #include <libraries/mui.h>
  9. #include <libraries/asl.h>
  10. #include <libraries/gadtools.h>
  11. #include <libraries/multiuser.h>
  12. #include <libraries/asl.h>
  13. #include <libraries/iffparse.h>
  14.  
  15. #include <proto/dos.h>
  16. #include <proto/exec.h>
  17. #include <proto/intuition.h>
  18. #include <proto/muimaster.h>
  19. #include <proto/asl.h>
  20. #include <proto/icon.h>
  21.  
  22. #define StringSucc(win,fromg,tog)\
  23.     DoMethod(fromg,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,\
  24.     win,3,MUIM_Set,MUIA_Window_ActiveObject,tog)
  25. #define SetButtonID(app,butobj,id)\
  26.     DoMethod(butobj,MUIM_Notify,MUIA_Pressed,FALSE,\
  27.         app,2,MUIM_Application_ReturnID,id)
  28. #define GetString(strobj,tostr,tempptr)\
  29.     { get(strobj,MUIA_String_Contents,&tempptr);\
  30.       strcpy(tostr,tempptr); }
  31.  
  32. char VersionTag[]="\0$VER: JoranEditUsers 1.0 (14.12.93)";
  33.  
  34. struct Library *MUIMasterBase;
  35. extern struct WBStartup *WBenchMsg;
  36. struct DiskObject *DiskObj;
  37.  
  38. char *PassFileName="RAM:passwd",*GroupFileName="RAM:multiuser.group";
  39. char *SucPassFileName=NULL;
  40. char *SucGroupFileName=NULL;
  41.  
  42. #define mySHELLSIZE 255
  43.  
  44. enum {
  45.     UserID_ID=1,
  46.     ChangedPasswd_ID,
  47.     ChangeBut_ID,
  48.     PasswdClose_ID,
  49.     AddGroup_ID,
  50.     DelGroup_ID,
  51.     GidClose_ID,
  52.     GidDblClk_ID,
  53.     GroupID_ID,
  54.     MainSave_ID,
  55.     MainCancel_ID,
  56.     CancelAddUser_ID,
  57.     AddUser_ID,
  58.     DelUser_ID,
  59.     AddUserOk_ID,
  60.     GroupID2_ID,
  61.     AddGid_ID,
  62.     AddGidCancel_ID,
  63.     AddGidOk_ID,
  64.     Admin_ID,
  65.     DelGid_ID
  66. };
  67.  
  68. //====== MainWin ==============
  69. APTR App,MainWin;
  70. APTR UserIDList,UserIDListview;
  71. APTR GroupIDList,GroupIDListview;
  72. APTR uidTxt,NameStr,HomeStr,PortStr;
  73. APTR ChangePasswdBut,AddGroupBut,DelGroupBut,EditGroupBut;
  74. APTR PasswdChk;
  75. APTR MainSave,MainCancel;
  76. APTR AddUserBut,DelUserBut;
  77. //========= GetGidWin ========
  78. APTR GetGidWin;
  79. APTR GidListview,GidList;
  80. //========= AddUserWin =======
  81. APTR AddUserWin;
  82. APTR UserIDStr,uidStr;
  83. APTR AddUserOkBut,AddUserCancelBut;
  84. //===== GroupWin =============
  85. APTR GroupWin,GidList2,GidListview2;
  86. APTR GidTxt,AdminTxt,AdminBut,GroupNameStr;
  87. APTR AddGidBut,DoneGidBut,DelGidBut;
  88. //======== AddGroupWin ========
  89. APTR AddGroupWin;
  90. APTR GroupIDStr,gidStr;
  91. APTR AddGroupOkBut,AddGroupCancelBut;
  92.  
  93. struct UserInfo {
  94.     struct Node UserNode;
  95.     char UserID[muUSERIDSIZE];
  96.     char Password[muPASSWORDSIZE];
  97.     UWORD uid,gid;
  98.     char UserName[muUSERNAMESIZE];
  99.     char HomeDir[muHOMEDIRSIZE];
  100.     char Shell[mySHELLSIZE];
  101. };
  102.  
  103. struct GroupInfo {
  104.     struct Node GroupNode;
  105.     char GroupID[muGROUPIDSIZE];
  106.     UWORD gid,MgsUid;
  107.     char GroupName[muGROUPNAMESIZE];
  108. };
  109.  
  110. struct ExtGroupInfo {
  111.     struct MinNode ExtGroupNode;
  112.     UWORD uid,gid;
  113. };
  114.  
  115. struct MinList UserList;
  116. struct MinList GroupList;
  117. struct MinList ExtGroupList;
  118.  
  119. struct UserInfo *CurUserInfo;
  120. struct GroupInfo *CurGroupInfo;
  121. struct GroupInfo *CurGidInfo;
  122.  
  123. struct FileRequester *HomeFileRequest;
  124.  
  125. ULONG __asm __saveds GidMultiHookFunc(register __a1 struct GroupInfo *,register __a2 char **);
  126. struct Hook GidMultiHook={0,0,GidMultiHookFunc,0,0};
  127. ULONG __asm __saveds PopupHomeHookFunc(register __a2 APTR);
  128. struct Hook PopupHomeHook={0,0,PopupHomeHookFunc,0,0};
  129.  
  130. ULONG __asm __saveds GidMultiHookFunc(register __a1 struct GroupInfo *gi,register __a2 char **cols)
  131. {
  132.     cols[0]=gi->GroupID;
  133.     cols[1]=gi->GroupName;
  134.  
  135.     return 0;
  136. }
  137.  
  138. ULONG __asm __saveds PopupHomeHookFunc(register __a2 APTR StrObj)
  139. {
  140.     struct Window *WinPtr;
  141.     APTR Path;
  142.  
  143.     if(!CurUserInfo) return 0;
  144.  
  145.     get(StrObj,MUIA_Window,&WinPtr);
  146.     get(StrObj,MUIA_String_Contents,&Path);
  147.     set(App,MUIA_Application_Sleep,TRUE);
  148.     if (MUI_AslRequestTags(HomeFileRequest,
  149.         ASLFR_Window,WinPtr,
  150.         ASLFR_InitialDrawer,Path,
  151.         TAG_DONE
  152.     ))
  153.     {
  154.         set(App,MUIA_Application_Sleep,FALSE);
  155.         set(StrObj,MUIA_String_Contents,HomeFileRequest->rf_Dir);
  156.     } else set(App,MUIA_Application_Sleep,FALSE);
  157.     
  158.     return 0;
  159. }
  160.  
  161. void GetArg(char *Line,char *Result)
  162. {
  163.     char *l=Line;
  164.     
  165.     while(*l!='|' && *l!='\n' && *l!='\0') *(Result++)=*(l++);
  166.     *Result='\0';
  167.     if(*l=='|') l++;
  168.     while(*l!='\n' && *l!='\0') *(Line++)=*(l++);
  169.     *Line='\0';
  170. }
  171.  
  172. int chrcnt(char *str,char c)
  173. {
  174.     int r=0;
  175.     while(*str) if(*(str++)==c) r++;
  176.     return r;
  177. }
  178.  
  179. struct UserInfo *GetUserInfo(UWORD uid)
  180. {
  181.     struct UserInfo *ui;
  182.     
  183.     for(ui=(struct UserInfo *)UserList.mlh_Head;ui!=(struct UserInfo *)&UserList.mlh_Tail;ui=(struct UserInfo *)ui->UserNode.ln_Succ)
  184.         if(ui->uid==uid) return ui;
  185.     return NULL;
  186. }
  187.  
  188. struct GroupInfo *GetGroupInfo(UWORD gid)
  189. {
  190.     struct GroupInfo *gi;
  191.     
  192.     for(gi=(struct GroupInfo *)GroupList.mlh_Head;gi!=(struct GroupInfo *)&GroupList.mlh_Tail;gi=(struct GroupInfo *)gi->GroupNode.ln_Succ)
  193.         if(gi->gid==gid) return gi;
  194.     return NULL;
  195. }
  196.  
  197. char *InitLists(void)
  198. {
  199.     FILE *UserFile=NULL,*GroupFile=NULL;
  200.     struct UserInfo *ui;
  201.     struct GroupInfo *gi;
  202.     struct ExtGroupInfo *egi;
  203.     char Line[512];
  204.     char Arg[512];
  205.     int error;
  206.     
  207.     NewList((struct List *)&UserList);
  208.     NewList((struct List *)&GroupList);
  209.     NewList((struct List *)&ExtGroupList);
  210.     
  211.     error=0;
  212.     if(!(UserFile=fopen(PassFileName,"r"))) error=errno;
  213.     if(!error &&!(GroupFile=fopen(GroupFileName,"r"))) error=errno;
  214.     
  215.     while(!error && fgets(Line,sizeof(Line),UserFile))
  216.     {
  217.         if(strlen(Line)<10) continue;
  218.         if(chrcnt(Line,'|')!=6) error=-2;
  219.         else if(ui=malloc(sizeof(struct UserInfo)))
  220.         {
  221.             GetArg(Line,ui->UserID);
  222.             if(!*ui->UserID) error=-2;
  223.             else 
  224.             {
  225.                 GetArg(Line,ui->Password);
  226.                 GetArg(Line,Arg);ui->uid=atoi(Arg);
  227.                 if(GetUserInfo(ui->uid)) error=-2;
  228.                 else
  229.                 {
  230.                     GetArg(Line,Arg);ui->gid=atoi(Arg);
  231.                     GetArg(Line,ui->UserName);
  232.                     GetArg(Line,ui->HomeDir);
  233.                     GetArg(Line,ui->Shell);
  234.                     ui->UserNode.ln_Name=ui->UserID;
  235.                     AddTail((struct List *)&UserList,(struct Node *)ui);
  236.                 }
  237.             }
  238.         } else error=-1;
  239.     }
  240.     
  241.     if(!error && errno) error=errno;
  242.     
  243.     while(!error && fgets(Line,sizeof(Line),GroupFile))
  244.     {
  245.         if(strlen(Line)<2) continue;
  246.         if(!strchr(Line,'|'))
  247.         {
  248.             char *p,*q;
  249.             UWORD uid,gid;
  250.             
  251.             if(p=strchr(Line,':'))
  252.             {
  253.                 *(p++)='\0';
  254.                 uid=atoi(Line);
  255.                 while(!error && *p)
  256.                 {
  257.                     if(q=strchr(p,',')) *(q++)='\0';
  258.                     else while(*q) q++;
  259.                     gid=atoi(p);
  260.                     p=q;
  261.                     if(egi=malloc(sizeof(struct ExtGroupInfo)))
  262.                     {
  263.                         egi->uid=uid;
  264.                         egi->gid=gid;
  265.                         AddTail((struct List *)&ExtGroupList,(struct Node *)egi);
  266.                     } else error=-1;
  267.                 }
  268.             } else error=-3;
  269.         }
  270.         else if(gi=malloc(sizeof(struct GroupInfo)))
  271.         {
  272.             if(chrcnt(Line,'|')!=3) error=-4;
  273.             else
  274.             {
  275.                 GetArg(Line,gi->GroupID);
  276.                 if(!*gi->GroupID) error=-4;
  277.                 else
  278.                 {
  279.                     GetArg(Line,Arg);gi->gid=atoi(Arg);
  280.                     if(GetGroupInfo(gi->gid)) error=-4;
  281.                     else
  282.                     {
  283.                         GetArg(Line,Arg);gi->MgsUid=atoi(Arg);
  284.                         GetArg(Line,gi->GroupName);
  285.                         gi->GroupNode.ln_Name=gi->GroupID;
  286.                         AddTail((struct List *)&GroupList,(struct Node *)gi);
  287.                     }
  288.                 }
  289.             }
  290.         } else error=-1;
  291.     }
  292.     
  293.     if(!error && errno) error=errno;
  294.         
  295.     if(UserFile) fclose(UserFile);
  296.     if(GroupFile) fclose(GroupFile);
  297.     
  298.     if(!error) return NULL;
  299.     switch(error) {
  300.         case -1:    return "Out of memory.";
  301.         case -2:    return "Error in Password file.";
  302.         case -3:    return "Error in first part of groupfile";
  303.         case -4:    return "Error in second part of groupfile";
  304.         default:    return strerror(error);
  305.     }
  306. }
  307.  
  308. char *SaveLists(char *PassName,char *GroupName)
  309. {
  310.     FILE *uf=NULL,*gf=NULL;
  311.     struct UserInfo *ui;
  312.     struct GroupInfo *gi;
  313.     struct ExtGroupInfo *egi;
  314.     static char npass[256],ngroup[256];
  315.     static char opass[256],ogroup[256];
  316.     int error;
  317.     
  318.     error=0;
  319.     
  320.     strcpy(npass,PassName);strcat(npass,".new");
  321.     strcpy(opass,PassName);strcat(opass,".old");
  322.     strcpy(ngroup,GroupName);strcat(ngroup,".new");
  323.     strcpy(ogroup,GroupName);strcat(ogroup,".old");
  324.     
  325.     unlink(opass);
  326.     unlink(ogroup);
  327.     if(!(uf=fopen(npass,"w"))) error=errno;
  328.     else if(!(gf=fopen(ngroup,"w"))) error=errno;
  329.     
  330.     if(!error) for(ui=(struct UserInfo *)UserList.mlh_Head;!error && ui!=(struct UserInfo *)&UserList.mlh_Tail;ui=(struct UserInfo *)ui->UserNode.ln_Succ)
  331.         if(fprintf(uf,"%s|%s|%d|%d|%s|%s|%s\n",
  332.             ui->UserID,ui->Password,ui->uid,ui->gid,
  333.             ui->UserName,ui->HomeDir,ui->Shell
  334.         )<0) error=errno;
  335.     if(!error) for(gi=(struct GroupInfo *)GroupList.mlh_Head;!error && gi!=(struct GroupInfo *)&GroupList.mlh_Tail;gi=(struct GroupInfo *)gi->GroupNode.ln_Succ)
  336.         if(fprintf(gf,"%s|%d|%d|%s\n",
  337.             gi->GroupID,gi->gid,gi->MgsUid,gi->GroupName
  338.         )<0) error=errno;
  339.     if(!error) if(fprintf(gf,"\n")<0) error=errno;
  340.     if(!error) for(ui=(struct UserInfo *)UserList.mlh_Head;!error && ui!=(struct UserInfo *)&UserList.mlh_Tail;ui=(struct UserInfo *)ui->UserNode.ln_Succ)
  341.     {
  342.         int cnt;
  343.         
  344.         cnt=0;
  345.         for(egi=(struct ExtGroupInfo *)ExtGroupList.mlh_Head;!error && egi!=(struct ExtGroupInfo *)&ExtGroupList.mlh_Tail;egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ)
  346.         {
  347.             if(egi->uid==ui->uid)
  348.             {
  349.                 if(cnt++) { if(fprintf(gf,",")<0) error=errno; }
  350.                 else { if(fprintf(gf,"%d:",ui->uid)<0) error=errno; }
  351.                 if(!error) if(fprintf(gf,"%d",egi->gid)<0) error=errno;
  352.             }
  353.         }
  354.         if(!error && cnt) if(fprintf(gf,"\n")<0) error=errno;
  355.     }
  356.  
  357.     if(uf) fclose(uf);
  358.     if(gf) fclose(gf);
  359.     
  360.     if(!error) if(rename(PassName,opass)) error=errno;
  361.     else if(rename(npass,PassName)) error=errno;
  362.     else if(rename(GroupName,ogroup)) error=errno;
  363.     else if(rename(ngroup,GroupName)) error=errno;
  364.     
  365.     if(!error) return NULL;
  366.     return strerror(error);
  367. }
  368.  
  369. void ToUserInfo(struct UserInfo *ui)
  370. {
  371.     char *tmpptr;
  372.     
  373.     GetString(NameStr,ui->UserName,tmpptr);
  374.     GetString(HomeStr,ui->HomeDir,tmpptr);
  375.     GetString(PortStr,ui->Shell,tmpptr);
  376. }
  377.  
  378. void ToGroupInfo(struct GroupInfo *gi)
  379. {
  380.     char *tmpptr;
  381.     
  382.     GetString(GroupNameStr,gi->GroupName,tmpptr);
  383. }
  384.  
  385. void ShowUserIds(void)
  386. {
  387.     struct UserInfo *ui;
  388.     char *p;
  389.     
  390.     DoMethod(UserIDList,MUIM_List_Clear);
  391.     set(UserIDList,MUIA_List_Quiet,TRUE);
  392.     for(ui=(struct UserInfo *)UserList.mlh_Head;ui!=(struct UserInfo *)&UserList.mlh_Tail;ui=(struct UserInfo *)ui->UserNode.ln_Succ)
  393.     {
  394.         p=ui->UserID;
  395.         DoMethod(UserIDList,MUIM_List_Insert,&p,1,MUIV_List_Insert_Sorted);
  396.     }
  397.     set(UserIDList,MUIA_List_Quiet,FALSE);
  398. }
  399.  
  400. char *GetGroupName(UWORD gid)
  401. {
  402.     struct GroupInfo *gi;
  403.     
  404.     if(gi=GetGroupInfo(gid)) return gi->GroupID;
  405.     return NULL;
  406. }
  407.  
  408. void AddGroupUser(UWORD uid,UWORD gid)
  409. {
  410.     struct ExtGroupInfo *egi;
  411.     struct UserInfo *ui;
  412.     
  413.     if(!(ui=GetUserInfo(uid)))
  414.     {
  415.         MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  416.             "User does not exist."
  417.         );
  418.         return;
  419.     }
  420.     if(!GetGroupInfo(gid))
  421.     {
  422.         MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  423.             "Group does not exist."
  424.         );
  425.         return;
  426.     }
  427.     if(ui->gid==gid)
  428.     {
  429.         MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  430.             "Group already exists."
  431.         );
  432.         return;
  433.     }
  434.     for(egi=(struct ExtGroupInfo *)ExtGroupList.mlh_Head;egi!=(struct ExtGroupInfo *)&ExtGroupList.mlh_Tail;egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ)
  435.     {
  436.         if(egi->uid==uid && egi->gid==gid)
  437.         {
  438.             MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  439.                 "Group already exists."
  440.             );
  441.             return;
  442.         }
  443.     }
  444.     if(egi=malloc(sizeof(struct ExtGroupInfo)))
  445.     {
  446.         egi->uid=uid;
  447.         egi->gid=gid;
  448.         AddTail((struct List *)&ExtGroupList,(struct Node *)egi);
  449.     }
  450.     else     MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  451.         "Not enough memory."
  452.     );
  453. }
  454.  
  455. void DelGroupUser(UWORD uid,UWORD gid)
  456. {
  457.     struct ExtGroupInfo *egi;
  458.     struct UserInfo *ui;
  459.     
  460.     if(!(ui=GetUserInfo(uid)))
  461.     {
  462.         MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  463.             "User does not exist."
  464.         );
  465.         return;
  466.     }
  467.     if(!GetGroupInfo(gid))
  468.     {
  469.         MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  470.             "Group does not exist."
  471.         );
  472.         return;
  473.     }
  474.     for(egi=(struct ExtGroupInfo *)ExtGroupList.mlh_Head;egi!=(struct ExtGroupInfo *)&ExtGroupList.mlh_Tail;egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ)
  475.     {
  476.         if(egi->uid==uid && egi->gid==gid)
  477.         {
  478.             Remove((struct Node *)egi);
  479.             free(egi);
  480.             return;
  481.         }
  482.     }
  483.     MUI_Request(App,MainWin,0,"Add Group To User","Hmmm",
  484.         "Group does not exist."
  485.     );
  486. }
  487.  
  488. void ShowGroups(UWORD uid)
  489. {
  490.     struct UserInfo *ui;
  491.     struct ExtGroupInfo *egi;
  492.     char *p;
  493.     
  494.     if(ui=GetUserInfo(uid))
  495.     {
  496.         p=GetGroupName(ui->gid);
  497.         set(GroupIDList,MUIA_List_Quiet,TRUE);
  498.         DoMethod(GroupIDList,MUIM_List_Clear);
  499.         DoMethod(GroupIDList,MUIM_List_Insert,&p,1,MUIV_List_Insert_Bottom);
  500.         for(egi=(struct ExtGroupInfo *)ExtGroupList.mlh_Head;egi!=(struct ExtGroupInfo *)&ExtGroupList.mlh_Tail;egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ)
  501.         {
  502.             if(ui->uid==egi->uid)
  503.             {
  504.                 p=GetGroupName(egi->gid);
  505.                 DoMethod(GroupIDList,MUIM_List_Insert,&p,1,MUIV_List_Insert_Bottom);
  506.             }
  507.         }
  508.         set(GroupIDList,MUIA_List_Quiet,FALSE);
  509.     }
  510. }
  511.  
  512. void SetUserInfo(void)
  513. {
  514.     char *userid;
  515.     struct UserInfo *ui;
  516.     static LONG ls=-1;
  517.     LONG ca;
  518.     
  519.     get(UserIDList,MUIA_List_Active,&ca);
  520.     if(ca==ls) return; else ls=ca;
  521.         
  522.     if(CurUserInfo) ToUserInfo(CurUserInfo);
  523.     
  524.     DoMethod(UserIDList,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&userid);
  525.     ui=(struct UserInfo *)FindName((struct List *)&UserList,userid);
  526.     if(ui)
  527.     {
  528.         char buf[20];
  529.         
  530.         CurUserInfo=ui;
  531.         sprintf(buf,"%d",ui->uid);
  532.         set(uidTxt,MUIA_Text_Contents,buf);
  533.         set(NameStr,MUIA_String_Contents,ui->UserName);
  534.         set(HomeStr,MUIA_String_Contents,ui->HomeDir);
  535.         set(PortStr,MUIA_String_Contents,ui->Shell);
  536.         set(PasswdChk,MUIA_Selected,*ui->Password!='\0');
  537.         ShowGroups(ui->uid);
  538.     } else
  539.     {
  540.         set(uidTxt,MUIA_Text_Contents,"");
  541.         set(NameStr,MUIA_String_Contents,"");
  542.         set(HomeStr,MUIA_String_Contents,"");
  543.         set(PortStr,MUIA_String_Contents,"");
  544.         set(PasswdChk,MUIA_Selected,FALSE);
  545.         DoMethod(GroupIDList,MUIM_List_Clear);
  546.         CurUserInfo=NULL;
  547.     }
  548. }
  549.  
  550. LONG GetGid(void)
  551. {
  552.     BOOL running=TRUE;
  553.     struct GroupInfo *gi;
  554.     APTR p;
  555.     LONG pos,ret=-1;
  556.     
  557.     set(App,MUIA_Application_Sleep,TRUE);
  558.     
  559.     DoMethod(GidList,MUIM_List_Clear);
  560.     set(GidList,MUIA_List_Quiet,TRUE);
  561.     for(gi=(struct GroupInfo *)GroupList.mlh_Head;gi!=(struct GroupInfo *)&GroupList.mlh_Tail;gi=(struct GroupInfo *)gi->GroupNode.ln_Succ)
  562.     {
  563.         p=gi;
  564.         DoMethod(GidList,MUIM_List_Insert,&p,1,MUIV_List_Insert_Bottom);
  565.     }
  566.     set(GidList,MUIA_List_Quiet,FALSE);
  567.     
  568.     set(GetGidWin,MUIA_Window_Open,TRUE);
  569.     
  570.     while(running)
  571.     {
  572.         ULONG sigs;
  573.         
  574.         switch(DoMethod(App,MUIM_Application_Input,&sigs))
  575.         {
  576.             case MUIV_Application_ReturnID_Quit:
  577.                 running=FALSE;
  578.                 DoMethod(App,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  579.                 break;
  580.             case GidClose_ID:
  581.                 running=FALSE;
  582.                 break;
  583.             case GidDblClk_ID:
  584.                 get(GidList,MUIA_List_Active,&pos);
  585.                 if(pos!=MUIV_List_Active_Off)
  586.                 {
  587.                     gi=(struct GroupInfo *)GroupList.mlh_Head;
  588.                     while(pos--) gi=(struct GroupInfo *)gi->GroupNode.ln_Succ;
  589.                     ret=gi->gid;
  590.                 }
  591.                 running=FALSE;
  592.                 break;
  593.         }
  594.         if (running && sigs) Wait(sigs);
  595.     }
  596.     
  597.     set(GetGidWin,MUIA_Window_Open,FALSE);
  598.     set(App,MUIA_Application_Sleep,FALSE);
  599.     
  600.     return ret;
  601. }
  602.  
  603. void SelectUid(int uid)
  604. {
  605. }
  606.  
  607. void DoAddUser(void)
  608. {
  609.     BOOL running=TRUE;
  610.     int uid,tuid;
  611.     struct UserInfo *ui;
  612.     char UserID[muUSERIDSIZE];
  613.     char *tmpptr;
  614.     
  615.     set(App,MUIA_Application_Sleep,TRUE);
  616.     set(AddUserWin,MUIA_Window_Open,TRUE);
  617.     set(UserIDStr,MUIA_String_Contents,"");
  618.     uid=1;tuid=-1;
  619.     while(uid!=tuid)
  620.     {
  621.         tuid=uid;
  622.         for(ui=(struct UserInfo *)UserList.mlh_Head;ui!=(struct UserInfo *)&UserList.mlh_Tail;ui=(struct UserInfo *)ui->UserNode.ln_Succ)
  623.             if(ui->uid==uid) uid++;
  624.     }
  625.     set(uidStr,MUIA_String_Integer,uid);
  626.     set(AddUserWin,MUIA_Window_ActiveObject,UserIDStr);
  627.     
  628.     while(running)
  629.     {
  630.         ULONG sigs;
  631.         
  632.         switch(DoMethod(App,MUIM_Application_Input,&sigs))
  633.         {
  634.             case MUIV_Application_ReturnID_Quit:
  635.                 running=FALSE;
  636.                 DoMethod(App,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  637.                 break;
  638.             case CancelAddUser_ID:
  639.                 running=FALSE;
  640.                 break;
  641.             case AddUserOk_ID:
  642.                 running=FALSE;
  643.                 GetString(UserIDStr,UserID,tmpptr);
  644.                 get(uidStr,MUIA_String_Integer,&uid);
  645.                 if(uid<1 || uid>65535) running=TRUE;
  646.                 if(!(*UserID)) running=TRUE;
  647.                 if(!running) for(ui=(struct UserInfo *)UserList.mlh_Head;ui!=(struct UserInfo *)&UserList.mlh_Tail;ui=(struct UserInfo *)ui->UserNode.ln_Succ)
  648.                 {
  649.                     if(ui->uid==uid || !strcmp(ui->UserID,UserID))
  650.                     {
  651.                         running=TRUE;
  652.                         break;
  653.                     }
  654.                 }
  655.                 if(running)
  656.                 {
  657.                     MUI_Request(App,AddUserWin,0,"Add Group To User","Ok",
  658.                         "Unallowed UserID or uid."
  659.                     );
  660.                 }
  661.                 else
  662.                 {
  663.                     if(ui=malloc(sizeof(struct UserInfo)))
  664.                     {
  665.                         strcpy(ui->UserID,UserID);
  666.                         ui->uid=uid;
  667.                         ui->gid=65535;
  668.                         *ui->UserName='\0';
  669.                         *ui->Password='\0';
  670.                         strcpy(ui->HomeDir,"SYS:Homes");
  671.                         strcpy(ui->Shell,"cli");
  672.                         ui->UserNode.ln_Name=ui->UserID;
  673.                         AddTail((struct List *)&UserList,(struct Node *)ui);
  674.                     }        
  675.                     ShowUserIds();
  676.                     SelectUid(uid);
  677.                 }
  678.                 break;
  679.         }
  680.         if (running && sigs) Wait(sigs);
  681.     }
  682.     
  683.     set(AddUserWin,MUIA_Window_Open,FALSE);
  684.     set(App,MUIA_Application_Sleep,FALSE);
  685. }
  686.  
  687. void DoAddGroup(void)
  688. {
  689.     LONG gid;
  690.     
  691.     if(!CurUserInfo) return;
  692.     if((gid=GetGid())==-1) return;
  693.     AddGroupUser(CurUserInfo->uid,gid);
  694.     ShowGroups(CurUserInfo->uid);
  695. }
  696.  
  697. void DoDelGroup(void)
  698. {
  699.     LONG pos;
  700.     LONG gid;
  701.     
  702.     get(GroupIDList,MUIA_List_Active,&pos);
  703.     if(pos!=MUIV_List_Active_Off)
  704.     {
  705.         if(pos==0)
  706.         {
  707.             if((gid=GetGid())!=-1)
  708.             {
  709.                     CurUserInfo->gid=gid;
  710.             }
  711.         }
  712.         else DelGroupUser(CurUserInfo->uid,CurGroupInfo->gid);
  713.         ShowGroups(CurUserInfo->uid);
  714.     }
  715. }
  716.  
  717. void SetCurGid(void)
  718. {
  719.     LONG pos;
  720.     struct ExtGroupInfo *egi;
  721.     
  722.     get(GroupIDList,MUIA_List_Active,&pos);
  723.     if(pos==0) CurGroupInfo=GetGroupInfo(CurUserInfo->gid);
  724.     else if(pos!=MUIV_List_Active_Off)
  725.     {
  726.         egi=(struct ExtGroupInfo *)ExtGroupList.mlh_Head;
  727.         while(egi->uid!=CurUserInfo->uid)
  728.             egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ;
  729.         pos--;
  730.         while(pos) 
  731.         {
  732.             if(egi->uid==CurUserInfo->uid) pos--;
  733.             egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ;
  734.         }
  735.         CurGroupInfo=GetGroupInfo(egi->gid);
  736.     } else CurGroupInfo=NULL;
  737. }
  738.  
  739. void DoDeletePasswd(void)
  740. {
  741.     if(CurUserInfo)
  742.     {
  743.         if(MUI_Request(App,MainWin,0,"Delete Password","Yes|Nope",
  744.             "Are you sure you want to delete the password?"
  745.         ))
  746.         {
  747.             CurUserInfo->Password[0]='\0';
  748.             set(PasswdChk,MUIA_Selected,FALSE);
  749.         }
  750.     }
  751. }
  752.  
  753. void DoSaveQuit(void)
  754. {
  755.     char *errmsg;
  756.     
  757.     if(CurUserInfo) ToUserInfo(CurUserInfo);
  758.     if(CurGidInfo) ToGroupInfo(CurGidInfo);
  759.     if(errmsg=SaveLists(PassFileName,GroupFileName))
  760.     {
  761.         MUI_Request(App,MainWin,0,"Save Files","Oops",
  762.                 "Error writing primary files.\n%s",errmsg
  763.         );
  764.         return;
  765.     }
  766.     
  767.     if(SucPassFileName && SucGroupFileName)    
  768.     {
  769.         if(errmsg=SaveLists(SucPassFileName,SucGroupFileName))
  770.         {
  771.             MUI_Request(App,MainWin,0,"Save Files","Oops",
  772.                     "Error writing secondary files.\n%s",errmsg
  773.             );
  774.             return;
  775.         }
  776.     }
  777.     
  778.     DoMethod(App,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  779. }
  780.  
  781. void DoDelUser(void)
  782. {
  783.     struct ExtGroupInfo *egi,*degi;
  784.     struct GroupInfo *gi;
  785.     
  786.     if(CurUserInfo)
  787.     {
  788.         if(CurUserInfo->uid==65535)
  789.         {
  790.             MUI_Request(App,MainWin,0,"Delete User","Oops",
  791.                 "You are not allowed to delete the root user."
  792.             );
  793.             return;
  794.         }
  795.         for(gi=(struct GroupInfo *)GroupList.mlh_Head;gi!=(struct GroupInfo *)&GroupList.mlh_Tail;gi=(struct GroupInfo *)gi->GroupNode.ln_Succ)
  796.         {
  797.             if(CurUserInfo->uid==gi->MgsUid)
  798.             {
  799.                 MUI_Request(App,MainWin,0,"Delete User","Oops",
  800.                     "This user is a group manager."
  801.                 );
  802.                 return;
  803.             }
  804.         }
  805.         if(!MUI_Request(App,MainWin,0,"Delete User","Yes|No",
  806.                 "Are you sure you want to delete the user \"%s\"?",
  807.                 CurUserInfo->UserID
  808.         )) return;
  809.     
  810.         // Delete the ExtGroupInfo
  811.         degi=NULL;
  812.         for(egi=(struct ExtGroupInfo *)ExtGroupList.mlh_Head;egi!=(struct ExtGroupInfo *)&ExtGroupList.mlh_Tail;egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ)
  813.         {
  814.             if(degi)
  815.             {
  816.                 Remove((struct Node *)degi);
  817.                 free(degi);
  818.                 degi=NULL;
  819.             }
  820.             if(egi->uid==CurUserInfo->uid) degi=egi;
  821.         }
  822.         if(degi)
  823.         {
  824.             Remove((struct Node *)degi);
  825.             free(degi);
  826.             degi=NULL;
  827.         }
  828.         // Delete user info
  829.         Remove((struct Node *)CurUserInfo);
  830.         free(CurUserInfo);
  831.         CurUserInfo=NULL;
  832.         ShowUserIds();
  833.     }
  834. }
  835.  
  836. void ShowGroupIds(void)
  837. {
  838.     struct GroupInfo *gi;
  839.     char *p;
  840.     
  841.     DoMethod(GidList2,MUIM_List_Clear);
  842.     set(GidList2,MUIA_List_Quiet,TRUE);
  843.     for(gi=(struct GroupInfo *)GroupList.mlh_Head;gi!=(struct GroupInfo *)&GroupList.mlh_Tail;gi=(struct GroupInfo *)gi->GroupNode.ln_Succ)
  844.     {
  845.         p=gi->GroupID;
  846.         DoMethod(GidList2,MUIM_List_Insert,&p,1,MUIV_List_Insert_Sorted);
  847.     }
  848.     set(GidList2,MUIA_List_Quiet,FALSE);
  849. }
  850.  
  851. void SetGroupInfo(void)
  852. {
  853.     char *groupid;
  854.     struct GroupInfo *gi;
  855.     static LONG ls=-1;
  856.     LONG ca;
  857.     
  858.     get(GidList2,MUIA_List_Active,&ca);
  859.     if(ca==ls) return; else ls=ca;
  860.         
  861.     if(CurGidInfo) ToGroupInfo(CurGidInfo);
  862.     
  863.     DoMethod(GidList2,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&groupid);
  864.     gi=(struct GroupInfo *)FindName((struct List *)&GroupList,groupid);
  865.     if(gi)
  866.     {
  867.         char buf[20];
  868.         struct UserInfo *ui;
  869.         
  870.         sprintf(buf,"%d",gi->gid);set(GidTxt,MUIA_Text_Contents,buf);
  871.         if(ui=GetUserInfo(gi->MgsUid)) set(AdminTxt,MUIA_Text_Contents,ui->UserID);
  872.         else set(AdminTxt,MUIA_Text_Contents,"\33bError");
  873.         set(GroupNameStr,MUIA_String_Contents,gi->GroupName);
  874.         CurGidInfo=gi;
  875.     } else
  876.     {
  877.         set(GidTxt,MUIA_Text_Contents,"");
  878.         set(AdminTxt,MUIA_Text_Contents,"");
  879.         set(GroupNameStr,MUIA_String_Contents,"");
  880.         CurGidInfo=NULL;
  881.     }
  882. }
  883.  
  884. void DoAddGid(void)
  885. {
  886.     BOOL running=TRUE;
  887.     int gid,tgid;
  888.     struct GroupInfo *gi;
  889.     char GroupID[muGROUPIDSIZE];
  890.     char *tmpptr;
  891.     
  892.     set(App,MUIA_Application_Sleep,TRUE);
  893.     set(AddGroupWin,MUIA_Window_Open,TRUE);
  894.     set(GroupIDStr,MUIA_String_Contents,"");
  895.     gid=0;tgid=-1;
  896.     while(gid!=tgid)
  897.     {
  898.         tgid=gid;
  899.         for(gi=(struct GroupInfo *)GroupList.mlh_Head;gi!=(struct GroupInfo *)&GroupList.mlh_Tail;gi=(struct GroupInfo *)gi->GroupNode.ln_Succ)
  900.             if(gi->gid==gid) gid++;
  901.     }
  902.     set(gidStr,MUIA_String_Integer,gid);
  903.     set(AddGroupWin,MUIA_Window_ActiveObject,GroupIDStr);
  904.     
  905.     while(running)
  906.     {
  907.         ULONG sigs;
  908.         
  909.         switch(DoMethod(App,MUIM_Application_Input,&sigs))
  910.         {
  911.             case MUIV_Application_ReturnID_Quit:
  912.                 running=FALSE;
  913.                 DoMethod(App,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  914.                 break;
  915.             case AddGidCancel_ID:
  916.                 running=FALSE;
  917.                 break;
  918.             case AddGidOk_ID:
  919.                 running=FALSE;
  920.                 GetString(GroupIDStr,GroupID,tmpptr);
  921.                 get(gidStr,MUIA_String_Integer,&gid);
  922.                 if(gid<0 || gid>65535) running=TRUE;
  923.                 if(!(*GroupID)) running=TRUE;
  924.                 if(!running) for(gi=(struct GroupInfo *)GroupList.mlh_Head;gi!=(struct GroupInfo *)&GroupList.mlh_Tail;gi=(struct GroupInfo *)gi->GroupNode.ln_Succ)
  925.                 {
  926.                     if(gi->gid==gid || !strcmp(gi->GroupID,GroupID))
  927.                     {
  928.                         running=TRUE;
  929.                         break;
  930.                     }
  931.                 }
  932.                 if(running)
  933.                 {
  934.                     MUI_Request(App,AddGroupWin,0,"Add Group","Ok",
  935.                         "Unallowed GroupID or gid."
  936.                     );
  937.                 }
  938.                 else
  939.                 {
  940.                     if(gi=malloc(sizeof(struct GroupInfo)))
  941.                     {
  942.                         strcpy(gi->GroupID,GroupID);
  943.                         gi->gid=gid;
  944.                         gi->MgsUid=65535;
  945.                         *gi->GroupName='\0';
  946.                         gi->GroupNode.ln_Name=gi->GroupID;
  947.                         AddTail((struct List *)&GroupList,(struct Node *)gi);
  948.                     }        
  949.                     ShowGroupIds();
  950.                 }
  951.                 break;
  952.         }
  953.         if (running && sigs) Wait(sigs);
  954.     }
  955.     
  956.     set(AddGroupWin,MUIA_Window_Open,FALSE);
  957.     set(App,MUIA_Application_Sleep,FALSE);
  958. }
  959.  
  960. void DoGetAdmin(void)
  961. {
  962.     if(!CurGidInfo) return;
  963.     if(!CurUserInfo)
  964.     {
  965.         MUI_Request(App,GroupWin,0,"Edit Groups","Ok",
  966.                         "Please select a user in the user window."
  967.         );
  968.         return;
  969.     }
  970.     CurGidInfo->MgsUid=CurUserInfo->uid;
  971.     set(AdminTxt,MUIA_Text_Contents,CurUserInfo->UserID);
  972. }
  973.  
  974. void DoDelGid(void)
  975. {
  976.     struct ExtGroupInfo *egi;
  977.     struct UserInfo *ui;
  978.     
  979.     if(!CurGidInfo) return;
  980.     
  981.     if(CurUserInfo->uid==65535)
  982.     {
  983.         MUI_Request(App,GroupWin,0,"Delete Group","Oops",
  984.             "You are not allowed to delete the root group."
  985.         );
  986.         return;
  987.     }
  988.     for(ui=(struct UserInfo *)UserList.mlh_Head;ui!=(struct UserInfo *)&UserList.mlh_Tail;ui=(struct UserInfo *)ui->UserNode.ln_Succ)
  989.     {
  990.         if(CurGidInfo->gid==ui->gid)
  991.         {
  992.             MUI_Request(App,GroupWin,0,"Delete Group","Oops",
  993.                 "This group is still used as primary group."
  994.             );
  995.             return;
  996.         }
  997.     }
  998.     for(egi=(struct ExtGroupInfo *)ExtGroupList.mlh_Head;egi!=(struct ExtGroupInfo *)&ExtGroupList.mlh_Tail;egi=(struct ExtGroupInfo *)egi->ExtGroupNode.mln_Succ)
  999.     {
  1000.         if(CurGidInfo->gid==egi->gid)
  1001.         {
  1002.             MUI_Request(App,GroupWin,0,"Delete Group","Oops",
  1003.                 "This group is still used as secondary group."
  1004.             );
  1005.             return;
  1006.         }
  1007.     }
  1008.     if(!MUI_Request(App,GroupWin,0,"Delete Group","Yes|No",
  1009.             "Are you sure you want to delete the group \"%s\"?",
  1010.             CurGidInfo->GroupID
  1011.     )) return;
  1012.  
  1013.     // Delete group info
  1014.     Remove((struct Node *)CurGidInfo);
  1015.     free(CurGidInfo);
  1016.     CurGidInfo=NULL;
  1017.     ShowGroupIds();
  1018. }
  1019.  
  1020. int GetIconInfo(void)
  1021. {
  1022.     char *tt;
  1023.     
  1024.     if(!(DiskObj=GetDiskObject(WBenchMsg->sm_ArgList->wa_Name))) return FALSE;
  1025.     if(tt=FindToolType(DiskObj->do_ToolTypes,"PRIMPASSFILE")) PassFileName=tt;
  1026.     if(tt=FindToolType(DiskObj->do_ToolTypes,"PRIMGROUPFILE")) GroupFileName=tt;
  1027.     if(tt=FindToolType(DiskObj->do_ToolTypes,"SUCCPASSFILE")) SucPassFileName=tt;
  1028.     if(tt=FindToolType(DiskObj->do_ToolTypes,"SUCCGROUPFILE")) SucGroupFileName=tt;
  1029.     return TRUE;
  1030. }
  1031.  
  1032.  
  1033. void main(int argc)
  1034. {
  1035.     BOOL running=TRUE;
  1036.     APTR dummy;
  1037.     char *errmsg;
  1038.     
  1039.     kputs("Test");
  1040.     
  1041.     if(!(MUIMasterBase=OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN))) exit(0);
  1042.     if(argc!=0)
  1043.     {
  1044.         fprintf(stderr,"Aaaaah... u are u-sing the CLI.\n");
  1045.         exit(0);
  1046.     }
  1047.         
  1048.     App = ApplicationObject,
  1049.         MUIA_Application_Title,        "EditUsers",
  1050.         MUIA_Application_Version,    "$VER: EditUsers 1.0 (11.9.93)",
  1051.         MUIA_Application_Copyright,"©1993 by Joran Jessurun",
  1052.         MUIA_Application_Author,    "Joran Jessurun",
  1053.         MUIA_Application_Base,        "EDITUSERS",
  1054.         MUIA_Application_Description,"Edit the multiuser database",
  1055.         SubWindow, MainWin=WindowObject,
  1056.             MUIA_Window_Title,        "EditUsers V1.0",
  1057.             MUIA_Window_ID,            MAKE_ID('E','U','M','A'),
  1058.             WindowContents,
  1059.             VGroup, 
  1060.                 Child, HGroup,
  1061.                     Child, VGroup,
  1062.                         GroupFrameT("userid's"),
  1063.                         Child, UserIDListview=ListviewObject,
  1064.                             MUIA_Listview_List,UserIDList=ListObject,
  1065.                                 ReadListFrame,
  1066.                                 MUIA_Listview_Input,TRUE,
  1067.                             End,
  1068.                         End,
  1069.                         Child, HGroup,
  1070.                             Child,AddUserBut=SimpleButton("Add"),
  1071.                             Child,DelUserBut=SimpleButton("Delete"),
  1072.                         End,
  1073.                     End,
  1074.                     Child, HSpace(2),
  1075.                     Child, VGroup,
  1076.                         Child, HGroup,
  1077.                             GroupFrameT("userinfo"),
  1078.                             Child, VGroup,
  1079.                                 Child, Label2("uid"),
  1080.                                 Child, Label2("name"),
  1081.                                 Child, Label2("home"),
  1082.                                 Child, Label2("port"),
  1083.                             End,
  1084.                             Child, VGroup,
  1085.                                 Child, uidTxt=TextObject,
  1086.                                     ReadListFrame,
  1087.                                 End,
  1088.                                 Child, NameStr=String("",muUSERNAMESIZE),
  1089.                                 Child, Popup(HomeStr,String("",muHOMEDIRSIZE),&PopupHomeHook,MUII_PopDrawer),
  1090.                                 Child, PortStr=String("",mySHELLSIZE),
  1091.                             End,
  1092.                         End,
  1093.                         Child, VGroup,
  1094.                             GroupFrameT("Password"),
  1095.                             Child, HGroup,
  1096.                                 Child, ChangePasswdBut=TextObject, ButtonFrame, 
  1097.                                     MUIA_Text_Contents, "Delete",
  1098.                                     MUIA_Text_PreParse, "\33c",
  1099.                                     MUIA_InputMode    , MUIV_InputMode_RelVerify,
  1100.                                     MUIA_Background   , MUII_ButtonBack,
  1101.                                     MUIA_Disabled,TRUE,
  1102.                                 End,
  1103.                                 Child, HSpace(0),
  1104.                                 Child, Label("Password Set"),
  1105.                                 Child, PasswdChk=ImageObject,
  1106.                                     ReadListFrame,
  1107.                                     MUIA_Image_Spec,MUII_CheckMark,
  1108.                                     MUIA_Image_FreeVert,TRUE,
  1109.                                     MUIA_Selected,FALSE,
  1110.                                     MUIA_Background,MUII_ButtonBack,
  1111.                                     MUIA_ShowSelState,FALSE,
  1112.                                 End,
  1113.                             End,
  1114.                         End,
  1115.                         Child, VGroup,
  1116.                             GroupFrameT("Group"),
  1117.                             Child, GroupIDListview=ListviewObject,
  1118.                                 MUIA_Listview_List,GroupIDList=ListObject,
  1119.                                     ReadListFrame,
  1120.                                 End,
  1121.                             End,
  1122.                             Child, HGroup,
  1123.                                 Child, AddGroupBut=SimpleButton("Add"),
  1124.                                 Child, DelGroupBut=SimpleButton("Delete"),
  1125.                                 Child, EditGroupBut=SimpleButton("Edit"),
  1126.                             End,
  1127.                         End,
  1128.                     End,
  1129.                 End,
  1130.                 Child, HGroup,
  1131.                     Child, MainSave=SimpleButton("Save"),
  1132.                     Child, HSpace(200),
  1133.                     Child, MainCancel=SimpleButton("Cancel"),
  1134.                 End,
  1135.             End,
  1136.         End,
  1137.         SubWindow, GetGidWin=WindowObject,
  1138.             MUIA_Window_Title,        "Select Group",
  1139.             MUIA_Window_ID,            MAKE_ID('E','U','G','G'),
  1140.             WindowContents,
  1141.             HGroup,
  1142.                 GroupFrameT("groups"),
  1143.                 Child, GidListview=ListviewObject,
  1144.                     MUIA_Listview_List, GidList=ListObject,
  1145.                         ReadListFrame,
  1146.                         MUIA_List_Format,",",
  1147.                         MUIA_List_DisplayHook,&GidMultiHook,
  1148.                     End,
  1149.                 End,
  1150.             End,
  1151.         End,
  1152.         SubWindow, GroupWin=WindowObject,
  1153.             MUIA_Window_Title,        "Edit Groups",
  1154.             MUIA_Window_ID,            MAKE_ID('E','U','G','W'),
  1155.             WindowContents,
  1156.             HGroup,
  1157.                 Child, HGroup,
  1158.                     MUIA_Weight,100,
  1159.                     GroupFrameT("groups"),
  1160.                     Child, GidListview2=ListviewObject,
  1161.                         MUIA_Listview_List, GidList2=ListObject,
  1162.                             ReadListFrame,
  1163.                         End,
  1164.                     End,
  1165.                 End,
  1166.                 Child, VGroup,
  1167.                     MUIA_Weight,200,
  1168.                     Child, HGroup,
  1169.                         GroupFrameT("group info"),
  1170.                         Child, VGroup,
  1171.                             Child, Label1("gid"),
  1172.                             Child, Label1("Manager"),
  1173.                             Child, Label2("GroupName"),
  1174.                         End,
  1175.                         Child, VGroup,
  1176.                             Child, GidTxt=TextObject,
  1177.                                 ReadListFrame,
  1178.                             End,
  1179.                             Child, HGroup,
  1180.                                 Child, AdminTxt=TextObject,
  1181.                                     ReadListFrame,
  1182.                                     MUIA_Weight,300,
  1183.                                 End,
  1184.                                 Child, AdminBut=TextObject,
  1185.                                     ButtonFrame,
  1186.                                     MUIA_Text_Contents,"Get",
  1187.                                     MUIA_InputMode,MUIV_InputMode_RelVerify,
  1188.                                     MUIA_Background,MUII_ButtonBack,
  1189.                                     MUIA_Weight,0,
  1190.                                 End,
  1191.                             End,
  1192.                             Child, GroupNameStr=String("",20),
  1193.                         End,
  1194.                     End,
  1195.                     Child, VSpace(0),
  1196.                     Child, HGroup,
  1197.                         Child, AddGidBut=SimpleButton("Add"),
  1198.                         Child, DelGidBut=SimpleButton("Delete"),
  1199.                         Child, DoneGidBut=SimpleButton("Done"),
  1200.                     End,
  1201.                 End,
  1202.             End,
  1203.         End,
  1204.         SubWindow, AddUserWin=WindowObject,
  1205.             MUIA_Window_Title,        "Add User ID",
  1206.             MUIA_Window_ID,            MAKE_ID('E','U','A','U'),
  1207.             WindowContents,
  1208.             VGroup,
  1209.                 Child, HGroup,
  1210.                     Child, VGroup,
  1211.                         Child, Label2("UserID"),
  1212.                         Child, Label2("uid"),
  1213.                     End,
  1214.                     Child, VGroup,
  1215.                         Child, UserIDStr=StringObject,
  1216.                             StringFrame,
  1217.                             MUIA_String_MaxLen,muUSERIDSIZE,
  1218.                             MUIA_String_Accept,"abcdefghijklmnopqrstuvwxyz"
  1219.                                                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1220.                                                      "1234567890",
  1221.                         End,
  1222.                         Child, uidStr=StringObject,
  1223.                             StringFrame,
  1224.                             MUIA_String_MaxLen,6,
  1225.                             MUIA_String_Integer,0,
  1226.                         End,
  1227.                     End,
  1228.                 End,
  1229.                 Child, HGroup,
  1230.                     Child, AddUserOkBut=SimpleButton("Ok"),
  1231.                     Child, HSpace(100),
  1232.                     Child, AddUserCancelBut=SimpleButton("Cancel"),
  1233.                 End,
  1234.             End,
  1235.         End,
  1236.         SubWindow, AddGroupWin=WindowObject,
  1237.             MUIA_Window_Title,        "Add Group ID",
  1238.             MUIA_Window_ID,            MAKE_ID('E','U','A','H'),
  1239.             WindowContents,
  1240.             VGroup,
  1241.                 Child, HGroup,
  1242.                     Child, VGroup,
  1243.                         Child, Label2("GroupID"),
  1244.                         Child, Label2("gid"),
  1245.                     End,
  1246.                     Child, VGroup,
  1247.                         Child, GroupIDStr=StringObject,
  1248.                             StringFrame,
  1249.                             MUIA_String_MaxLen,muGROUPIDSIZE,
  1250.                             MUIA_String_Accept,"abcdefghijklmnopqrstuvwxyz"
  1251.                                                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1252.                                                      "1234567890",
  1253.                         End,
  1254.                         Child, gidStr=StringObject,
  1255.                             StringFrame,
  1256.                             MUIA_String_MaxLen,6,
  1257.                             MUIA_String_Integer,0,
  1258.                         End,
  1259.                     End,
  1260.                 End,
  1261.                 Child, HGroup,
  1262.                     Child, AddGroupOkBut=SimpleButton("Ok"),
  1263.                     Child, HSpace(100),
  1264.                     Child, AddGroupCancelBut=SimpleButton("Cancel"),
  1265.                 End,
  1266.             End,
  1267.         End,
  1268.     End;
  1269.  
  1270.     if(!App)
  1271.     {
  1272.         MUI_Request(NULL,NULL,0,"AdresBase V3.0 MUI","Hmmm",
  1273.             "Error initialising program."
  1274.         );
  1275.         exit(0);
  1276.     }
  1277.     
  1278.     // Install notify's to main program
  1279.     DoMethod(MainWin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1280.         App,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  1281.     DoMethod(UserIDList,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,
  1282.         App,2,MUIM_Application_ReturnID,UserID_ID);
  1283.     DoMethod(GroupIDList,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,
  1284.         App,2,MUIM_Application_ReturnID,GroupID_ID);
  1285.     DoMethod(ChangePasswdBut,MUIM_Notify,MUIA_Pressed,FALSE,
  1286.         App,2,MUIM_Application_ReturnID,ChangeBut_ID);
  1287.     DoMethod(AddGroupBut,MUIM_Notify,MUIA_Pressed,FALSE,
  1288.         App,2,MUIM_Application_ReturnID,AddGroup_ID);
  1289.     DoMethod(DelGroupBut,MUIM_Notify,MUIA_Pressed,FALSE,
  1290.         App,2,MUIM_Application_ReturnID,DelGroup_ID);
  1291.     DoMethod(GetGidWin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1292.         App,2,MUIM_Application_ReturnID,GidClose_ID);
  1293.     DoMethod(GidListview,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  1294.         App,2,MUIM_Application_ReturnID,GidDblClk_ID);
  1295.     DoMethod(PasswdChk,MUIM_Notify,MUIA_Selected,TRUE,
  1296.         ChangePasswdBut,3,MUIM_Set,MUIA_Disabled,FALSE);
  1297.     DoMethod(PasswdChk,MUIM_Notify,MUIA_Selected,FALSE,
  1298.         ChangePasswdBut,3,MUIM_Set,MUIA_Disabled,TRUE);
  1299.     SetButtonID(App,MainSave,MainSave_ID);
  1300.     SetButtonID(App,MainCancel,MUIV_Application_ReturnID_Quit);
  1301.     SetButtonID(App,AddUserBut,AddUser_ID);
  1302.     DoMethod(AddUserWin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1303.         App,2,MUIM_Application_ReturnID,CancelAddUser_ID);
  1304.     SetButtonID(App,AddUserOkBut,AddUserOk_ID);
  1305.     SetButtonID(App,AddUserCancelBut,CancelAddUser_ID);
  1306.     DoMethod(UserIDStr,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  1307.         App,2,MUIM_Application_ReturnID,AddUserOk_ID);
  1308.     SetButtonID(App,DelUserBut,DelUser_ID);
  1309.     DoMethod(EditGroupBut,MUIM_Notify,MUIA_Pressed,FALSE,
  1310.         GroupWin,3,MUIM_Set,MUIA_Window_Open,TRUE);
  1311.     DoMethod(GroupWin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1312.         GroupWin,3,MUIM_Set,MUIA_Window_Open,FALSE);
  1313.     DoMethod(GidList2,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,
  1314.         App,2,MUIM_Application_ReturnID,GroupID2_ID);
  1315.     SetButtonID(App,AddGidBut,AddGid_ID);
  1316.     SetButtonID(App,AddGroupCancelBut,AddGidCancel_ID);
  1317.     SetButtonID(App,AddGroupOkBut,AddGidOk_ID);
  1318.     DoMethod(AddGroupWin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1319.         App,2,MUIM_Application_ReturnID,AddGidCancel_ID);
  1320.     DoMethod(GroupIDStr,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  1321.         App,2,MUIM_Application_ReturnID,AddGidOk_ID);
  1322.     SetButtonID(App,AdminBut,Admin_ID);
  1323.     DoMethod(DoneGidBut,MUIM_Notify,MUIA_Pressed,FALSE,
  1324.         GroupWin,3,MUIM_Set,MUIA_Window_Open,FALSE);
  1325.     SetButtonID(App,DelGidBut,DelGid_ID);
  1326.     DoMethod(MainWin,MUIM_Window_SetCycleChain,
  1327.         UserIDListview,AddUserBut,DelUserBut,
  1328.         NameStr,HomeStr,PortStr,
  1329.         ChangePasswdBut,
  1330.         GroupIDListview,
  1331.         AddGroupBut,DelGroupBut,EditGroupBut,
  1332.         MainSave,MainCancel,
  1333.         NULL
  1334.     );
  1335.     DoMethod(AddUserWin,MUIM_Window_SetCycleChain,
  1336.         UserIDStr,uidStr,
  1337.         AddUserOkBut,AddUserCancelBut,
  1338.         NULL
  1339.     );
  1340.     DoMethod(GetGidWin,MUIM_Window_SetCycleChain,
  1341.         GidListview,
  1342.         NULL
  1343.     );
  1344.     DoMethod(GroupWin,MUIM_Window_SetCycleChain,
  1345.         GidListview2,
  1346.         AdminBut,GroupNameStr,
  1347.         AddGidBut,DelGidBut,DoneGidBut,
  1348.         NULL
  1349.     );
  1350.     DoMethod(AddGroupWin,MUIM_Window_SetCycleChain,
  1351.         GroupIDStr,gidStr,
  1352.         AddGroupOkBut,AddGroupCancelBut,
  1353.         NULL
  1354.     );
  1355.  
  1356.     // Openen main window
  1357.     set(MainWin,MUIA_Window_Open,TRUE);
  1358.     
  1359.     if(!GetIconInfo())
  1360.     {
  1361.         MUI_Request(App,MainWin,0,"Edit Users","Hmmm",
  1362.             "Error getting diskobject."
  1363.         );
  1364.         running=FALSE;
  1365.     }
  1366.     else if(errmsg=InitLists())
  1367.     {
  1368.         MUI_Request(App,MainWin,0,"Edit Users","Hmmm",
  1369.             errmsg
  1370.         );
  1371.         running=FALSE;
  1372.     }
  1373.     else if(!(HomeFileRequest=(struct FileRequester *)MUI_AllocAslRequestTags(
  1374.         ASL_FileRequest,
  1375.         ASLFR_SleepWindow,TRUE,
  1376.         ASLFR_TitleText,"Select home directory",
  1377.         ASLFR_DoSaveMode,TRUE,
  1378.         ASLFR_DrawersOnly,TRUE,
  1379.         ASLFR_RejectIcons,TRUE,
  1380.         TAG_DONE
  1381.     )))
  1382.     {
  1383.         MUI_Request(App,MainWin,0,"Edit Users","Wuk",
  1384.             "Error allocating FileRequester."
  1385.         );
  1386.         running=FALSE;
  1387.     }
  1388.     else
  1389.     {
  1390.         ShowUserIds();
  1391.         ShowGroupIds();
  1392.     }
  1393.  
  1394.     while (running)
  1395.     {
  1396.        ULONG signals;
  1397.  
  1398.        switch (DoMethod(App,MUIM_Application_Input,&signals))
  1399.        {
  1400.             case MUIV_Application_ReturnID_Quit:
  1401.                 running = FALSE;
  1402.                 break;
  1403.             case UserID_ID:        SetUserInfo();            break;    
  1404.             case AddGroup_ID:        DoAddGroup();            break;
  1405.             case GroupID_ID:        SetCurGid();            break;
  1406.             case DelGroup_ID:        DoDelGroup();            break;
  1407.             case ChangeBut_ID:    DoDeletePasswd();        break;
  1408.             case MainSave_ID:        DoSaveQuit();            break;
  1409.             case AddUser_ID:        DoAddUser();            break;
  1410.             case DelUser_ID:        DoDelUser();            break;
  1411.             case GroupID2_ID:        SetGroupInfo();        break;
  1412.             case AddGid_ID:        DoAddGid();                break;
  1413.             case Admin_ID:            DoGetAdmin();            break;
  1414.             case DelGid_ID:        DoDelGid();                break;
  1415.        }
  1416.  
  1417.        if (running && signals) Wait(signals);
  1418.     }
  1419.     
  1420.     if(HomeFileRequest) MUI_FreeAslRequest(HomeFileRequest);
  1421.     if(App) DisposeObject(App);
  1422.     if(MUIMasterBase) CloseLibrary(MUIMasterBase);
  1423. }
  1424.